﻿
@{
    ViewBag.Title = "InfoEditView";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
}


<div style="margin-top:10px;">
    <form class="layui-form" id="FormInfo">
        <div class="layui-form-item">
            <label class="layui-form-label">主项目选择</label>
            <div class="layui-input-block">
                <select name="ProjectId" lay-verify="required" lay-search>
                    <option value=""></option>
                    @for (int i = 0; i < ViewBag.ProjectList.Count; i++)
                    {
                        <option value="@ViewBag.ProjectList[i]["ProjectId"]">@ViewBag.ProjectList[i]["Name"]|@ViewBag.ProjectList[i]["ProjectCode"]|@ViewBag.ProjectList[i]["Type"]</option>
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">合同名称</label>
            <div class="layui-input-inline" style="width:300px;">
                <input type="text" name="HTMC" value="@ViewBag.HTMC" required lay-verify="required" placeholder="请输入合同名称" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">合同类型</label>
            <div class="layui-input-inline">
                <input type="text" name="HTLX" value="@ViewBag.HTLX" required lay-verify="required" placeholder="请输入合同类型" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">对方单位名称</label>
            <div class="layui-input-inline" style="width:300px;">
                <input type="text" name="DFDWMC" value="@ViewBag.DFDWMC" required lay-verify="required" placeholder="请输入对方单位名称" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">合同金额</label>
            <div class="layui-input-inline">
                <input type="number" name="HTJE" value="@ViewBag.HTJE" required lay-verify="required" placeholder="请输入合同金额" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">结算方式</label>
            <div class="layui-input-block" style="width:800px;">
                <textarea name="JSFS" placeholder="请输入结算方式" class="layui-textarea">@ViewBag.JSFS</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">支付方式</label>
            <div class="layui-input-block" style="width:800px;">
                <textarea name="ZFFS" placeholder="请输入支付方式" class="layui-textarea">@ViewBag.ZFFS</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" id="mysubmit" class="layui-btn" lay-submit lay-filter="formVerify" style="display:none;">立即提交</button>
                <button type="button" class="layui-btn" id="BtnSave">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<script>
    var SubContractId = "@ViewBag.SubContractId";
    var ProjectId = "@ViewBag.ProjectId";
    var state = "";
    layui.use([ 'form', 'laydate'], function(){
        var form = layui.form;
        var laydate = layui.laydate;
        var IsValidate = 0;

        //选中下拉菜单
        if (ProjectId != "") {
            $("select[name=ProjectId]").find("option[value='" + ProjectId + "']").attr("selected", true);
            form.render();
            //layui.form().render(); //这是1.0的写法
            //layui.form.render();  //这是2.0更新后的写法
            //$("#myselect").val(state);
        }


        //拦截form提交消息
        form.on('submit(formVerify)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            IsValidate = 1;
            return false;
        });

        laydate.render({
            elem: '#BidTime' //指定元素
        });

        $("#BtnSave").on("click", function () {

            $("#mysubmit").click();
            if (IsValidate == 1) {
                IsValidate = 0;
                var obj = $("#FormInfo").serializeArray();
                var data = {};
                $.each(obj, function (i, v) {
                    data[v.name] = v.value;
                });
                if (SubContractId == "") {
                    //表示新增
                    $.ajax({
                        type: "POST",
                        url: "/SubContract/ConAdd",
                        async: false,
                        contentType: "application/json",
                        dataType: "json",
                        data: JSON.stringify(data),
                        success: function (msg) {
                            if (msg.result == "OK") {
                                parent.layer.msg('新增成功,记得刷新列表', { icon: 6, time: 1000 });
                                //parent.table.reload("demo");
                                //var index = parent.layer.getFrameIndex(window.name);
                                //parent.layer.close(index);

                                parent.layui.admin.events.closeThisTabs();
                            } else {
                                alert(msg.result);
                            }
                        }
                    });


                }
                else {
                    //表示编辑
                    data["SubContractId"] = SubContractId;
                    $.ajax({
                        type: "POST",
                        url: "/SubContract/ConUpdate",
                        async: false,
                        contentType: "application/json",
                        dataType: "json",
                        data: JSON.stringify(data),
                        success: function (msg) {
                            if (msg.result == "OK") {
                                parent.layer.msg('修改成功,记得刷新列表', { icon: 6, time: 1000 });
                                //parent.table.reload("demo");
                                //var index = parent.layer.getFrameIndex(window.name);
                                //parent.layer.close(index);

                                parent.layui.admin.events.closeThisTabs();
                            } else {
                                alert(msg.result);
                            }
                        }
                    });
                }
            }
        });









    });
</script>


